﻿using System;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using DAL;
using Common;


public partial class Business_Business_Finish : System.Web.UI.Page
{
    protected int CurPage;

    protected int PageSize = Convert.ToInt32(ConfigurationSettings.AppSettings["PageSize"]);

    protected string Type
    {
        get { return string.IsNullOrEmpty(Request["type"]) ? "1,2,3,4,5,6" : Request["type"].ToString(); }
    }

    protected string MenuType;

    protected string Query;

    protected int UserType = 0;


    protected void Page_Load(object sender, EventArgs e)
    {
        CurPage = string.IsNullOrEmpty(Request["curpage"]) ? 1 : Convert.ToInt32(Request["curpage"]);
        MenuType = string.IsNullOrEmpty(Request["menutype"]) ? "" : Request["menutype"].ToString();
        Query = string.IsNullOrEmpty(Request["Query"]) ? "all" : Request["Query"].ToString();
        UserType = Convert.ToInt32(Session["UserType"]);

        if (!this.IsPostBack)
        {   
            List<NewsType> NewsTypeList = new Sys_Para().SelectNewsType();
            foreach (NewsType nt in NewsTypeList)
                ClsID.Items.Add(new ListItem("┣ " + nt.TypeName, nt.TypeKey.ToString()));


            OneDate.Attributes.Add("onclick", "selectDate(this)");
            TwoDate.Attributes.Add("onclick", "selectDate(this)");


            //条件 Hashtable

            Hashtable tb = new Hashtable();
            bool QueryAdd = false;

            if (Query != "")
            {
                tb.Add("Query", Query);
                QueryAdd = true;
            }

            if (MenuType != "")
            {
                tb.Add("MenuType", MenuType);
                QueryAdd = true;
            }

            if ( Type!="" )
            {
                tb.Add("Type", Type);
                QueryAdd = true;
            }

            if (!string.IsNullOrEmpty(Request.QueryString["ClsID"]))
            {   
                tb.Add("ClsID", Request["ClsID"].ToString());
                QueryAdd = true;
                ClsID.SelectedValue = Request.QueryString["ClsID"].ToString();
            }
            if (!string.IsNullOrEmpty(Request.QueryString["txt_Type"]))
            {
                tb.Add("txt_Type", Request["txt_Type"].ToString());
                QueryAdd = true;
                txt_Type.SelectedValue = Request.QueryString["txt_Type"].ToString();
            }
            if (!string.IsNullOrEmpty(Request.QueryString["Keyword"]))
            {
                tb.Add("Keyword", Request.QueryString["Keyword"].ToString().Trim());
                QueryAdd = true;
                Keyword.Text = Request.QueryString["Keyword"].ToString().Trim();
            }
            if (!string.IsNullOrEmpty(Request.QueryString["OneDate"]))
            {
                tb.Add("OneDate", Request.QueryString["OneDate"].ToString().Trim());
                QueryAdd = true;
                OneDate.Text = Request["OneDate"].ToString().Trim();
            }
            if (!string.IsNullOrEmpty(Request.QueryString["TwoDate"]))
            {
                tb.Add("TwoDate", Request.QueryString["TwoDate"].ToString().Trim());
                QueryAdd = true;
                TwoDate.Text = Request.QueryString["TwoDate"].ToString().Trim();
            }
            tb = QueryAdd ? tb : null;

            NewsDataBind(tb);
        }
    }

    private void NewsDataBind(Hashtable QueryTable)
    {
        string URL = "Business.aspx?menutype=" + MenuType + "&type=" + Type;

        Pager1.SetPageInfo(CurPage, new News().SelectNewsCount(QueryTable), URL, QueryTable);

        Re_News.DataSource = new News().SelectNews(QueryTable, CurPage);
        Re_News.DataBind();
    }

    //搜索
    protected void submit_Click(object sender, EventArgs e)
    {
        CurPage = 1;

        Hashtable tb = new Hashtable();
        bool QueryAdd = false;

        //条件 Hashtable

        if (MenuType != "")
        {
            tb.Add("MenuType", MenuType);
            QueryAdd = true;
        }

        if ( Type != "")
        {
            tb.Add("Type", Type);
            QueryAdd = true;
        }
       
        if (!string.IsNullOrEmpty(ClsID.SelectedValue))
        {
            tb.Add("ClsID", ClsID.SelectedValue);
            QueryAdd = true;
        }
        if (!string.IsNullOrEmpty(txt_Type.SelectedValue))
        {
            tb.Add("txt_Type", txt_Type.SelectedValue);
            QueryAdd = true;
        }
        if (!string.IsNullOrEmpty(Keyword.Text.Trim()))
        {
            tb.Add("Keyword", Keyword.Text.Trim());
            QueryAdd = true;
        }
        if (OneDate.Text.Trim() != "选择开始日期")
        {
            tb.Add("OneDate", OneDate.Text.Trim());
            QueryAdd = true;
        }
        if (TwoDate.Text.Trim() != "选择结束日期")
        {
            tb.Add("TwoDate", TwoDate.Text.Trim());
            QueryAdd = true;
        }
        tb = QueryAdd ? tb : null;

        NewsDataBind(tb);
    }

    //
    protected void Re_News_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int NewsKey = Convert.ToInt32(e.CommandArgument);

        if (e.CommandName=="del")
        {
            new News().DelNews(NewsKey);
        }

        Hashtable tb = new Hashtable();
        bool QueryAdd = false;

        //条件 Hashtable
        if (Type != "finish")
        {
            tb.Add("Type", Type);
            QueryAdd = true;
        }

        if (!string.IsNullOrEmpty(ClsID.SelectedValue))
        {
            tb.Add("ClsID", ClsID.SelectedValue);
            QueryAdd = true;
        }
        if (!string.IsNullOrEmpty(txt_Type.SelectedValue))
        {
            tb.Add("txt_Type", txt_Type.SelectedValue);
            QueryAdd = true;
        }
        if (!string.IsNullOrEmpty(Keyword.Text.Trim()))
        {
            tb.Add("Keyword", Keyword.Text.Trim());
            QueryAdd = true;
        }
        if (OneDate.Text.Trim() != "选择开始日期")
        {
            tb.Add("OneDate", OneDate.Text.Trim());
            QueryAdd = true;
        }
        if (TwoDate.Text.Trim() != "选择结束日期")
        {
            tb.Add("TwoDate", TwoDate.Text.Trim());
            QueryAdd = true;
        }
        tb = QueryAdd ? tb : null;

        NewsDataBind(tb);
    }


    protected void Re_News_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (UserType == 1)
        {
            ((HtmlTableCell)e.Item.FindControl("SheduleTime")).Visible = false;
            ((HtmlTableCell)e.Item.FindControl("DoTime")).Visible = false;
        }


        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            if (UserType == 2 || UserType == 4)
                ((LinkButton)e.Item.FindControl("del")).Visible = Account.ShowForUserTypeList1("133", MenuType);
            else
                ((LinkButton)e.Item.FindControl("del")).Visible = false;
        }
    }

    protected string GetUserRealName(int UserKey)
    {
        Sys_Account account = new Account().GetAccountByKey(Convert.ToInt32(Eval("UserKey")));
        return (account == null) ? "" : account.RealName;
    }

    protected string GetKaoQinStatus(object HuiDan,object TechFiveTime)
    {
        if (HuiDan == null)
            return "正常";
        else
        {
            if (HuiDan.ToString() == "正常")
                return "正常";
            else
            {
                string kq_str = "迟到";
                kq_str +=  (Convert.ToDateTime(TechFiveTime) - Convert.ToDateTime(TechFiveTime.ToString().Split(' ')[0] + " 09:15:00")).Hours.ToString() + "时";
                kq_str +=  (Convert.ToDateTime(TechFiveTime) - Convert.ToDateTime(TechFiveTime.ToString().Split(' ')[0] + " 09:15:00")).Minutes.ToString() + "分";
                return kq_str;
            }
        }
    }

    protected string GetQuery(string Query)
    {
        string query = "";
        switch (Query)
        {
            case "all":
                query = "全部";
                break;
            case "day":
                query = "当天";
                break;
            case "month":
                query = "当月";
                break;
        }
        return query;
    }
}
